package com.demo.biz.dubboservice.rabbitmq;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;


@Service
public class ProducerService {
	
	@Value("${mq.queue}")
	private String queue;

	@Autowired
	private AmqpTemplate amqpTemplate;
	
	private static String exchange_key = "_exchange";//交换机
	private static String queue_key = "_patt";//queue与交换机绑定的路由

	public void sendQueue(Object object) {
		// convertAndSend 将Java对象转换为消息发送至匹配key的交换机中Exchange
		amqpTemplate.convertAndSend(queue+exchange_key, queue+queue_key, object);
	}
	
	public void sendQueue(String exchange_key, String queue_key, Object object) {
		// convertAndSend 将Java对象转换为消息发送至匹配key的交换机中Exchange
		amqpTemplate.convertAndSend(exchange_key, queue_key, object);
	}
	
}
